package com.beyondcreative.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class StyleBeanOpenHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "stylebean.db";
	private static final int DATABASE_VERSION = 1;

	public static class DoListColumns implements BaseColumns {
		public static final String TABLE_NAME = "dolist";
		public static final String CN_CONTENT = "content"; // Text
		public static final String CN_IMPORTANCE = "importance";// 0,1,2
		public static final String CN_DAY = "day";// Text
		public static final int CN_IMPORTANCE_red = 0;
		public static final int CN_IMPORTANCE_cryon = 1;
		public static final int CN_IMPORTANCE_green = 2;
		public static final int CN_DAY_YESTERDAY = 0;
		public static final int CN_DAY_TODAY = 1;
		public static final int CN_DAY_TOMORROW = 2;
		public static final int CN_DAY_LATER = 3;
		public static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME
				+ " (" + DoListColumns._ID + " INTEGER PRIMARY KEY,"
				+ CN_CONTENT + " TEXT," + CN_IMPORTANCE + " INTEGER," + CN_DAY
				+ " TEXT" + ");";
	}

	private Context mContext;

	public StyleBeanOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		mContext = context;

	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		try {
			db.execSQL(DoListColumns.TABLE_CREATE);
			/*
			 * ContentValues values = new ContentValues();
			 * values.put(DoListColumns.CN_CONTENT,
			 * mContext.getResources().getString(R.string.infoText1));
			 * values.put(DoListColumns.CN_DAY, "today");
			 * values.put(DoListColumns.CN_IMPORTANCE, 0);
			 * db.insert(DoListColumns.TABLE_NAME,null, values);
			 * values.put(DoListColumns.CN_CONTENT,
			 * mContext.getResources().getString(R.string.infoText2));
			 * values.put(DoListColumns.CN_IMPORTANCE, 1);
			 * db.insert(DoListColumns.TABLE_NAME,null, values);
			 * values.put(DoListColumns.CN_CONTENT,
			 * mContext.getResources().getString(R.string.infoText3));
			 * db.insert(DoListColumns.TABLE_NAME,null, values);
			 * values.put(DoListColumns.CN_CONTENT,
			 * mContext.getResources().getString(R.string.infoText4));
			 * db.insert(DoListColumns.TABLE_NAME,null, values);
			 */
			/*
			 * values.put(DoListColumns.CN_IMPORTANCE, 2);
			 * values.put(DoListColumns.CN_CONTENT,
			 * mContext.getResources().getString(R.string.infoText4));
			 * db.insert(DoListColumns.TABLE_NAME,null, values);
			 */
		} catch (Exception SQLException) {
			Log.d("Ahn",
					"onCreate exception invoked:" + SQLException.getMessage());
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// Logs that the database is being upgraded
		Log.w("Ahn", "Upgrading database from version " + oldVersion + " to "
				+ newVersion + ", which will destroy all old data");

		// Kills the table and existing data
		db.execSQL("DROP TABLE IF EXISTS " + DoListColumns.TABLE_NAME);

		// Recreates the database with a new version
		onCreate(db);

	}

}
